#include "AiboWalkControl.h"


AiboWalkControl::AiboWalkControl( WalkInstructionHandler* walkHandler)
{
	this->setWalkHandler( walkHandler );
	this->setWalkSpeed( 0.0f );
	this->setTurnSpeed( 0.0f );
}

AiboWalkControl::~AiboWalkControl(void)
{
}

void AiboWalkControl::walkForward()
{
	if( this->getWalkHandler() != NULL ) {
		this->getWalkHandler()->addInstruction( WalkForwardInstruction( this->getWalkSpeed() ) );
	}
}

void AiboWalkControl::walkForward( float walkSpeed )
{
	this->setWalkSpeed( walkSpeed );
	this->walkForward();
}

void AiboWalkControl::walkBackward()
{
	if( this->getWalkHandler() != NULL ) {
		this->getWalkHandler()->addInstruction( WalkForwardInstruction( this->getWalkSpeed() * -1.0f ) );
	}
}

void AiboWalkControl::walkBackward( float walkSpeed )
{
	this->setWalkSpeed( walkSpeed );
	this->walkBackward();
}

void AiboWalkControl::turnLeft()
{
	if( this->getWalkHandler() != NULL ) {
		this->getWalkHandler()->addInstruction( WalkRotateInstruction( this->getTurnSpeed() ) );
	}
}

void AiboWalkControl::turnLeft( float turnSpeed )
{
	this->setTurnSpeed( turnSpeed );
	this->turnLeft();
}

void AiboWalkControl::turnRight()
{
	if( this->getWalkHandler() != NULL ) {
		this->getWalkHandler()->addInstruction( WalkRotateInstruction( this->getTurnSpeed() * -1.0f ) );
	}
}

void AiboWalkControl::turnRight( float turnSpeed )
{
	this->setTurnSpeed( turnSpeed );
	this->turnLeft();
}

void AiboWalkControl::strafeRight()
{
	if( this->getWalkHandler() != NULL ) {
		this->getWalkHandler()->addInstruction( WalkStrafeInstruction( this->getWalkSpeed() * 1.0f ) );
	}
}

void AiboWalkControl::strafeRight( float strafeSpeed )
{
	this->setWalkSpeed( strafeSpeed );
	this->strafeRight();
}

void AiboWalkControl::strafeLeft()
{
	if( this->getWalkHandler() != NULL ) {
		this->getWalkHandler()->addInstruction( WalkStrafeInstruction( this->getWalkSpeed() ) );
	}
}

void AiboWalkControl::strafeLeft( float strafeSpeed )
{
	this->setWalkSpeed( strafeSpeed );
	this->strafeLeft();
}

void AiboWalkControl::stopWalk()
{
	if( this->getWalkHandler() != NULL ) {
		this->getWalkHandler()->addInstruction( WalkForwardInstruction( RESET_SPEED ) );
	}
}

void AiboWalkControl::stopTurn()
{
	if( this->getWalkHandler() != NULL ) {
		this->getWalkHandler()->addInstruction( WalkRotateInstruction( RESET_SPEED ) );
	}
}

void AiboWalkControl::stopStrafe()
{
	if( this->getWalkHandler() != NULL ) {
		this->getWalkHandler()->addInstruction( WalkStrafeInstruction( RESET_SPEED ) );
	}
}

void AiboWalkControl::setWalkSpeed( float walkSpeed )
{
	if( walkSpeed < 0.0f ) {
		walkSpeed *= -1.0f;
	}
	if( walkSpeed <= 1.0 )
		this->m_walkSpeed = walkSpeed;
	else
		this->m_walkSpeed = 1.0f;
}

void AiboWalkControl::setTurnSpeed( float turnSpeed )
{
	if( turnSpeed < 0 ) {
		turnSpeed *= -1.0f;
	}
	if( turnSpeed <= 1.0 )
		this->m_turnSpeed = turnSpeed;
	else
		this->m_turnSpeed = 1.0f;
}